package com.tender.service.impl;

import cn.hutool.core.lang.Assert;
import com.tender.domain.ShiroRole;
import com.tender.domain.ShiroRoleExample;
import com.tender.domain.ShiroRoleCondition;
import com.tender.service.ShiroRoleService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

import com.tender.utils.DataUtils;

import com.tender.mapper.ShiroRoleMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

@Service
public class ShiroRoleServiceImpl implements ShiroRoleService {

    @Autowired
    private ShiroRoleMapper shiroRoleMapper;

    @Override
    public ShiroRole selectOne(ShiroRoleCondition param) {
        Assert.notNull(param.getRowId(), "角色rowId不能为空");
        ShiroRoleExample example = new ShiroRoleExample();
        ShiroRoleExample.Criteria criteria = example.createCriteria();

        DataUtils.setLongValueIfNotNull(param.getRowId(), criteria::andRowIdEqualTo);

        List<ShiroRole> shiroRoles = shiroRoleMapper.selectByExample(example);
        return CollectionUtils.isEmpty(shiroRoles) ? null : shiroRoles.get(0);
    }

    @Override
    public List<ShiroRole> selectList(ShiroRoleCondition param) {
        ShiroRoleExample example = new ShiroRoleExample();
        ShiroRoleExample.Criteria criteria = example.createCriteria();

        DataUtils.setValueIfNotBlank(param.getLabel(), criteria::andLabelEqualTo);
        DataUtils.setValueIfNotBlank(param.getRoleNameLike(), roleNameLike -> criteria.andRoleNameLike(DataUtils.likeIn(roleNameLike)));

        List<ShiroRole> shiroRoles = shiroRoleMapper.selectByExample(example);

        return CollectionUtils.isEmpty(shiroRoles) ? new ArrayList<>() : shiroRoles;
    }

    @Override
    public int updateByCondition(ShiroRoleCondition param) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(ShiroRoleCondition param) {
        return 0;
    }

    @Override
    public int insertSelective(ShiroRole param) {
        return 0;
    }

    @Override
    public int insertListSelective(List<ShiroRole> params) {
        return 0;
    }

    @Override
    public int deleteByCondition(ShiroRoleCondition param) {
        return 0;
    }

    @Override
    public int deleteByPrimaryKey(Long rowId) {
        Assert.notNull(rowId, "角色rowId不能为空");
        ShiroRoleExample example = new ShiroRoleExample();
        ShiroRoleExample.Criteria criteria = example.createCriteria();
        criteria.andRowIdEqualTo(rowId);

        return shiroRoleMapper.deleteByExample(example);
    }
}
